package org.aldar.bquest.entity;

import org.aldar.bquest.constants.IConstants;
import org.aldar.bquest.constants.LandscapeType;
import org.aldar.bquest.entity.pool.TilesPool;
import org.aldar.bquest.logic.controller.level.LevelController;
import org.andengine.util.math.MathUtils;

/**
 * User: Daria
 * Date: 5/31/13 8:09 PM
 */
public class TileSpriteUtil implements IConstants {
    public static TileSprite getRandomTile(final int row, final int col, float alpha) {
        int style = MathUtils.random(0, LevelController.getCurrentLevel().lsTypesBoard.length - 1);
        TileSprite tileSprite = TilesPool.getSpriteForStyle(LevelController.getCurrentLevel().lsTypesBoard[style], col, row);
        tileSprite.getLsSprite().setAlpha(alpha);
        tileSprite.setMapPosition(col, row);
        return tileSprite;
    }

    public static TileSprite getRandomTile(final int row, final int col) {
        return getRandomTile(row, col, 1);
    }

    public static TileSprite getMagicTile(final int row, final int col) {
        TileSprite tileSprite = TilesPool.getSpriteForCrystalTile(col, row);
        tileSprite.setStyle(LandscapeType.CRYSTAL);
        tileSprite.getLsSprite().setAlpha(1);
        tileSprite.setMapPosition(col, row);
        return tileSprite;
    }

    public static void releaseTile(TileSprite tile) {
        TilesPool.pushToStack(tile);
    }

    public static TileSprite getAbilityTile(int row, int col) {
        TileSprite tileSprite = TilesPool.getSpriteForAbilityTile(col, row);
        tileSprite.setStyle(LandscapeType.CRYSTAL_ABILITY);
        tileSprite.getLsSprite().setAlpha(1);
        tileSprite.setMapPosition(col, row);
        return tileSprite;
    }

    public static float getTileCenterX(float tileX) {
        return tileX + 50;
    }

    public static float getTileCenterY(float tileY) {
        return tileY - 55;
    }

    public static TileSprite getBigCrystalTile(int row, int col) {
        TileSprite tileSprite = TilesPool.getSpriteForBigCrystalTile(col, row);
        tileSprite.setStyle(LandscapeType.BIGCRYSTAL);
        tileSprite.getLsSprite().setAlpha(1);
        tileSprite.setMapPosition(col, row);
        return tileSprite;
    }
}
